package edu.gdkm.service.impl;

import edu.gdkm.service.ProductService;
import edu.gdkm.sql.dao.CategoryMapper;
import edu.gdkm.sql.dao.ProductDetailMapper;
import edu.gdkm.sql.dao.ProductMapper;
import edu.gdkm.sql.pojo.Category;
import edu.gdkm.sql.pojo.Product;
import edu.gdkm.sql.pojo.ProductDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductMapper productMapper;
    @Autowired
    CategoryMapper categoryMapper;
    @Autowired
    ProductDetailMapper productDetailMapper;

    @Override
    public String showProduct(String name) {
        Product product = productMapper.findByGoodsname(name);
        Category category = categoryMapper.findById(product.getTypeid());
        ProductDetail productDetail = productDetailMapper.getProductDetailByProductId(product.getId());
        return (product + "\n" + category + "\n" + productDetail);
    }

    @Override
    public int insertProduct(Product product) {
        return productMapper.insertProduct(product);
    }
}
